package com.xl.rentkeeper.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.xl.fuse.protos.CmdConst;
import com.xl.rentkeeper.mgr.IUiObserver;
import com.xl.rentkeeper.mgr.UiObserverManager;

/**
 *
 * @描述: 基类的fragment
 * Created by Jerry on 2015/7/13.
 */
public abstract class BaseFragment extends Fragment implements CmdConst,IUiObserver
{
	// 获取宿主,也就是当前的activity
	protected FragmentActivity mActivity;

	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		//获取宿主,也就是当前的activity
		mActivity = getActivity();
		UiObserverManager.getInstance().registerEvent(monitorEvents(), this);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
	{
		return initView();
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState)
	{
		super.onActivityCreated(savedInstanceState);

		initData();
	}

	protected abstract View initView();

	/**
	 * 如果子类需要加载数据，就复写此方法
	 */
	protected void initData()
	{

	}

	public String[] monitorEvents() {
		return new String[]{CMD_USER_LOGIN};
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		UiObserverManager.getInstance().unregisterEvent(monitorEvents(), this);
	}
}
